package com.elsa.server.demo.controller;

import java.security.Principal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.elsa.server.demo.service.IHelloService;

@RestController
public class DemoController {
	
    @Autowired
    private IHelloService helloService;
    //Feign调用测试
    @GetMapping("hello")
    public String hello(String name){
        return this.helloService.hello(name);
    }
    
    
	@GetMapping("demo1")
	@PreAuthorize("hasAnyAuthority('user:add')")
	public String demo1() {
		return "拥有'user:add'权限";
	}

	@GetMapping("demo2")
	@PreAuthorize("hasAnyAuthority('user:update')")
	public String demo2() {
		return "拥有'user:update'权限";
	}

	@GetMapping("user")
	public Principal currentUser(Principal principal) {
		return principal;
	}
}
